<template>
<view>
<!--logs.wxml-->
<view class="top-warps">
   <view @tap="search" class="top-input">
      <icon type="search" size="12" class="index_icon"></icon>
      <input class="fr" disabled="true" placeholder="搜索品牌或商品"></input>
   </view>
</view>
<view class="classify-warp">
   <!--左侧栏-->
   <view class="classify-left">
      <view v-for="(item, index) in cateleft" :key="index" @tap="getStatus" :class="'normal ' + (index === status ? 'active' : '')" :data-index="index">{{item.cat_name}}</view>
   </view>
   <!--右侧栏-->
   <view class="classify-right">
      <view v-for="(item, index) in cateright" :key="index" class="content" @tap="liebiao" :data-index="index" v-if="show == false">
         <view class="article">
            <image :src="item.thumb_img"></image>
            <view>{{item.cat_name}}</view>
         </view>
      </view>
      <view v-if="show">
         <image src="/static/remao_shop/img/NODATA (2).png" class="nodata"></image>
         <text class="noData"> 暂无数据</text>
      </view>
      <!-- <view class="classify-right">
      <view wx:for="{{cateleft[status].children}}" wx:key="">
        <view wx:if="{{item.goodsList}}">
          <view class='pro-title'>
            <image></image>
            <text>{{item.cateright}}</text>
            <image></image>
          </view>
          <view wx:for="{{item.cateright}}" class='article' wx:key="">
            <navigator url="../details/details">
              <image src="{{item.thumb_img}}"></image>
              <text>{{item.cat_name}}</text>
            </navigator>
          </view>
        </view>
        <view wx:else>
          <view class='article fl'>
            <navigator url="../details/details">
              <image src="{{item.thumb_img}}"></image>
              <text>{{item.cat_name}}</text>
            </navigator>
          </view>
        </view>
      </view>
    </view> -->
   </view>
</view>
</view>
</template>

<script>
// var util = require('../../utils/util.js');
// import request from '../../utils/requestUtils.js';
// import {
//   xcxId,
//   category_url,
// } from "../../utils/data.js";
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      status: 0,
      cateleft: [],
      cateright: [],
      name: '',
      index: [],
      show: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中'
    });
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.onLoad();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList: function () {
      app.globalData.request({
        url: api.default.index_list,
        data: {
          cat_id: ''
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        dataType: 'json',
        responseType: 'text',
        success: res => {
          this.setData({
            cateleft: res.one,
            cateright: res.two
          }), console.log(this.cateright);

          if (this.cateright.length == 0) {
            this.setData({
              show: true
            });
          }

          wx.hideLoading();
        },
        fail: function (err) {
          this.setData({
            show: true
          });
        },
        complete: function (res) {}
      });
    },

    getStatus(e) {
      // console.log(e)
      this.setData({
        status: e.currentTarget.dataset.index
      });
      var i = this.status;
      console.log(this.cateleft[i].cat_id);
      var id = this.cateleft[i].cat_id;
      console.log(this.status);
      app.globalData.request({
        url: api.default.index_list,
        data: {
          cat_id: id
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        dataType: 'json',
        responseType: 'text',
        success: res => {
          this.setData({
            cateleft: res.one,
            cateright: res.two
          });
          var number = this.cateright.length;
          console.log(number);

          if (number == 0) {
            this.setData({
              show: true
            });
          } else {
            this.setData({
              show: false
            });
          }

          console.log(res);
        },
        fail: function (res) {},
        complete: function (res) {}
      });
    },

    //搜索页面
    search: function () {
      wx.navigateTo({
        url: '../../packageB/search/search'
      });
    },
    //跳转分类商品列表
    liebiao: function (event) {
      console.log(event);
      console.log(event.currentTarget.dataset.index);
      let index = event.currentTarget.dataset.index;
      var id = this.cateright[index].ID;
      wx.navigateTo({
        url: '../../packageB/listClassified/listClassified?ID=' + id
      });
    }
  }
};
</script>
<style>
@import "./logs.css";
</style>